<!--
 * @Description: 商家远程任务 - 查看详情
 * @Author: liyujie
 * @Date: 2021/08/03
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/08/03
-->
<template>
    <section class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <div class="header-title">
                    查看详情
                </div>
                <div class="project-info">
                    <div class="project-info-item">
                        项目名称：{{ project_info.project_title }}
                    </div>
                    <div class="project-info-item">
                        企业参与数：{{ project_info.shop_count }}
                    </div>
                </div>
            </div>
            <!-- /header -->
            <!-- 筛选-->
            <div class="filter-view">
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        企业名称
                    </p>
                    <el-input
                        placeholder="请输入企业名称"
                        v-model="filterData.company_name"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 260px"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        任务状态
                    </p>
                    <el-select
                        v-model="filterData.status"
                        size="medium"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in statusList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        class="query-button"
                        @click="getTableData(1)"
                    >
                        查询
                    </el-button>
                    <el-button
                        type="text"
                        @click="handleReset()"
                    >
                        重置
                    </el-button>
                </div>
            </div>
            <!--筛选-->
            <!-- table -->
            <div class="table-wrapper">
                <el-table
                    :data="tableData"
                    height="100%"
                    style="width: 100%;"
                    ref="table"
                    class="data-table"
                    :cell-style="{height: '40px'}"
                    v-loading="tableLoading"
                >
                    <el-table-column
                        label="序号"
                        align="center"
                        width="80"
                        type="index"
                        fixed="left"
                    />
                    <el-table-column
                        prop="company_name"
                        label="商家名称"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        prop="task_title"
                        label="任务名称"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        prop="accept_count"
                        label="用户参与数(人)"
                        align="center"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        label="任务状态"
                        align="center"
                    >
                        <template slot-scope="scope">
                            <div class="status-wrapper">
                                <div
                                    class="status-dot"
                                    :class="['status-dot', scope.row.status === 1 ? 'success' : 'normal']"
                                />
                                <div>{{ scope.row.status | statusFilter }}</div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="操作"
                        align="left"
                    >
                        <template slot-scope="scope">
                            <div class="option-btn-group">
                                <el-button
                                    type="text"
                                    size="medium"
                                    @click="beforeDelete(scope.row)"
                                >
                                    移除
                                </el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <!-- /table -->
            <!-- /分页 -->
            <div class="pagination-wrapper clearfix">
                <el-pagination
                    layout="total, prev, pager, next, jumper"
                    background
                    :current-page.sync="page.now_page"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />
            </div>
        </div>
        <!-- 确认移除弹窗 -->
        <el-dialog
            title="移除任务"
            :visible.sync="deleteDialog"
            width="640px"
            :close-on-click-modal="false"
            class="reject-dialog"
            @close="reason = ''"
        >
            <div class="reject-tips">
                <div class="icon">
                    <i class="el-icon-warning"/>
                </div>
                <div class="content">
                    移除后，用户端该任务将不再展示，商家冻结的奖励也会返回给商家，用户正在进行中的任务会被视为未完成，该操作为危险操作请谨慎
                </div>
            </div>
            <div class="reject-title is-required"><span style="color: #FF3030">*</span>移除原因</div>
            <el-input
                v-model="reason"
                type="textarea"
                :autosize="{ minRows: 4, maxRows: 6}"
                placeholder="请输入移除原因"
                :maxlength="100"
                show-word-limit
            />
            <div
                class="dialog-footer"
            >
                <el-button
                    size="medium"
                    type="default"
                    :style="{width: '100px', marginRight: '32px'}"
                    @click="deleteDialog = false"
                >
                    取消
                </el-button>
                <el-button
                    type="primary"
                    size="medium"
                    :style="{width: '100px'}"
                    :disabled="!reason"
                    @click="handleDelete(task_no, reason)"
                >
                    确认移除
                </el-button>
            </div>
        </el-dialog>
    </section>
</template>

<script>
import { back } from '@/mixin/back';

export default {
    name: 'ShopProjectDetail',
    mixins: [back],
    components: {},
    data() {
        return {
            filterData: {
                shop_project_no: '',
                company_name: '',
                status: 99
            },
            project_info: {
                project_title: '',
                shop_count: 0,
            },
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            statusList: [
                {label: '全部', value: 99},
                {label: '进行中', value: 1},
                {label: '未进行', value: -1},
            ],
            task_no: '',
            reason: '',
            deleteDialog: false,
            authResult: {}
        };
    },
    computed: {},
    filters: {
        statusFilter(val) {
            switch (val) {
                case 1:
                    return '进行中';
                case -1:
                    return '未进行';
                default:
                    return '--';
            }
        },
    },
    watch: {},
    mounted() {
        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '工作'}, {title: '商家远程项目'}, {title: '项目管理列表', path: '/student/shop-project-list'}, {title: '查看详情'}]);
        this.authResult = this.$route.meta.authResult;
        this.filterData.shop_project_no = this.$route.query.shop_project_no;
        this.project_info.project_title = this.$route.query.project_title;
        this.getTableData();
    },

    methods: {

        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {
            this.tableLoading = true;
            let params = { ...this.filterData };

            params.page_id = page || this.page.now_page;
            this.$post('/student/task_stuagent_shop_project%5Cget_project_detail_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                    this.page = res.data.page;
                    if(res.data.shop_count) {
                        this.project_info.shop_count = res.data.shop_count;
                    }
                } else {
                    this.$notify({
                        title: '提示',
                        message: res.msg,
                        type: 'warning'
                    });
                }
                this.tableLoading = false;
            });
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },

        /**
         * 重置筛选条件
         */
        handleReset() {
            this.filterData = {
                shop_project_no: this.$route.query.shop_project_no,
                company_name: '',
                status: 99
            };
            this.getTableData(1);
        },

        /**
         * 删除提示
         * @param row
         */
        beforeDelete(row) {
            this.task_no = row.task_no;
            this.deleteDialog = true;
        },

        /**
         * 确认删除
         * @param task_no
         * @param reason
         */
        handleDelete(task_no, reason) {
            this.$post('/student/task_stuagent_shop_project%5Cremove_task', {
                task_no,
                reason
            }, res => {
                if (res.code === 1) {
                    this.$notify({
                        title: '提示',
                        message: '移除成功',
                        type: 'success'
                    });
                    this.deleteDialog = false;
                    this.getTableData();
                } else {
                    this.$notify({
                        title: '提示',
                        message: res.msg,
                        type: 'warning'
                    });
                }
            });
        }

    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        background: #fff;
        box-sizing: border-box;

        /*header*/

        .header {
            height: 68px;
            padding: 24px;
            box-sizing: border-box;
            box-shadow: 0px -1px 0px 0px #F0F2F5;
            display: flex;
            align-items: center;
            border-bottom: 1px solid #F0F2F5;

            .header-title {
                color: #333333;
                font-size: 20px;
                height: 20px;
                font-weight: 500;
                position: relative;
                margin: 24px 0 24px 12px;

                &::before {
                    content: '';
                    position: absolute;
                    left: -8px;
                    top: -1px;
                    width: 3px;
                    height: 20px;
                    background: #1890FF;
                }
            }
            .project-info {
                height: 100%;
                display: flex;
                align-items: flex-end;
                margin-left: 16px;
                font-size: 14px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #2FBDB3;
                .project-info-item {
                    font-size: 14px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #2FBDB3;
                    margin-right: 24px;
                }
            }
        }

        /*筛选*/

        .filter-view {
            box-sizing: border-box;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            padding: 0 24px;
            margin-top: 12px;

            .header-new-box {
                display: flex;
                align-items: center;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                white-space: nowrap;
                margin-right: 24px;
                margin-bottom: 12px;

                &-title {
                    margin-right: 16px;
                    white-space: nowrap;
                }
                .query-button  {
                    width: 84px;
                    height: 36px;
                    background: #FFFFFF;
                    border-radius: 4px;
                    border: 1px solid #1890FF;
                    font-size: 14px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #1890FF;
                    margin-right: 12px;
                }
            }
        }

        // 表格
        .table-wrapper {
            padding: 0 24px;
            flex: 1;
            height: 0;
            .cell-title {
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #333333;
                margin-bottom: 12px;
                display: -webkit-box;
                -webkit-box-orient: vertical;
                overflow: hidden;
                -webkit-line-clamp: 2;
            }
            .cell-content {
                display: -webkit-box;
                -webkit-box-orient: vertical;
                overflow: hidden;
                -webkit-line-clamp: 3;
            }
            .cell-tips {
                color: #999;
            }
        }
        .data-table {
            ::-webkit-scrollbar {
                width: 6px;
                height: 6px;
            }
            // 操作按钮
            .option-btn-group {
                .el-button {
                    margin-left: 0;
                    margin-right: 10px;
                }
            }
        }
        .status-wrapper {
            display: flex;
            align-items: center;
            justify-content: center;

            .status-dot {
                width: 6px;
                height: 6px;
                border-radius: 50%;
                margin-right: 5px;

                &.success {
                    background: #4CD964;
                }

                &.danger {
                    background: #FF3030;
                }

                &.warning {
                    background: #FFA72D;
                }

                &.normal {
                    background: #A6A6A6;
                }
            }
        }

        /* 分页 */
        .pagination-wrapper {
            padding: 12px 24px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    /deep/ .el-dialog__body {
        padding: 0;
    }
    /deep/ .el-textarea__inner {
        resize: none;
    }
    /deep/ .el-table__fixed-right {
        right: 6px!important;
    }
    /deep/ .el-table {
        th {
            background: #f2f2f2!important;
            font-size: 14px!important;
            font-family: PingFangSC-Medium, PingFang SC!important;
            font-weight: 500!important;
            color: #333333!important;
            height: 44px!important;
        }
    }
    .reject-dialog {
        .reject-tips {
            display: flex;
            align-items: flex-start;
            margin-bottom: 24px;
            .icon {
                font-size: 16px;
                margin-right: 10px;
                margin-top: 3px;
                color: #F95B56;
            }
            .content {
                font-size: 14px;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #666666;
                line-height: 22px;
            }
        }
        .reject-title {
            font-size: 14px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #333333;
            margin-bottom: 12px;
        }
        /deep/ .el-dialog__footer {
            text-align: center;
            padding: 0 0 30px;
            margin-top: 6px;
        }

        /deep/ .el-dialog__body {
            padding: 24px 64px;
        }
    }

    .dialog-footer {
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: 24px;
    }
}
</style>
